﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcMusicStore.Models;
using Webdiyer.WebControls.Mvc;

namespace MvcMusicStore.Controllers
{
    public class StoreController : Controller
    {
        MusicStoreEntities storeDB = new MusicStoreEntities();
        //
        // GET: /Store/

        public ActionResult Index(int? id)
        {
            PagedList<Genre> genres = storeDB.Genres.OrderBy(c => c.GenreId).ToPagedList(id??1,2);//针对Mvcpager做的
          if (Request.IsAjaxRequest())
            {
                return PartialView("AjaxList",genres);
            }
            return View(genres);
          
        }
        [ChildActionOnly]
        public ActionResult AjaxList()
        {
            return PartialView("AjaxList");
        }
       
        public ActionResult Details(int id)
        {
            var album = storeDB.Albums.Find(id);
            return View(album);
        }
        public ActionResult Browse(string genre)
        {
            //var genreModel = storeDB.Genres.Include("Albums").Single(g=>g.Name==genre);
            //return View(genreModel);
            var genree = storeDB.Genres.Single(g => g.Name == genre);
            var genreModel = from c in storeDB.Albums
                             where c.GenreId == genree.GenreId
                             select c;
            return View(genreModel);
        }


    }
}
